<img src="<?php echo BASE_URL; ?>images/logo-agua.png" class="left" />
<label class="tit-relat">Relatório Mensal</label>
<label class="tit-periodo"><?php echo $data[4]->mes; ?>/<?php echo $data[3]; ?></label>

<table class="tbl-relatorio">
    <thead>
        <tr>
            <th>Entrada</th>
            <th>Membro</th>
            <th>Pagamento</th>
            <th>Tesoureiro</th>
            <th>Data</th>
            <th>Valor</th>
        </tr>
    </thead>
    <tbody>
        <?php
        $total_entrada = 0;
        $total_saida = 0;

        $total_dizimo = 0;
        $total_oferta = 0;
        $total_outra_entradas = 0;

        $total_dinheiro = 0;
        $total_cartao = 0;
        $total_cheque = 0;

        foreach ($data[0] as $entrada) {
            echo "<tr>";

            echo "<td>" . $entrada->beanTipoEntrada->descricao . "</td>";
            echo "<td>" . $entrada->beanMembro->nome . "</td>";

            echo "<td>" . $entrada->beanTipoPagamento->tipoPagamento . "</td>";
            echo "<td>" . $entrada->beanTesoureiro->beanMembro->nome . "</td>";

            echo "<td>" . $entrada->data . "</td>";
            echo "<td class='valor'>" . number_format($entrada->valor, 2) . "</td>";

            echo "</tr>";


            $total_entrada += $entrada->valor;

            // guarda os valores do tipo de entrada
            if ($entrada->beanTipoEntrada->codigo == 1) {
                $total_dizimo += $entrada->valor;
            } elseif ($entrada->beanTipoEntrada->codigo == 2) {
                $total_oferta += $entrada->valor;
            } else {
                $total_outra_entradas += $entrada->valor;
            }

            // guarda os valores do tipo de pagamento
            if ($entrada->beanTipoPagamento->codigo == 1) {
                $total_dinheiro += $entrada->valor;
            } elseif ($entrada->beanTipoPagamento->codigo == 2) {
                $total_cartao += $entrada->valor;
            } else {
                $total_cheque += $entrada->valor;
            }
        }

        if (empty($data[0])) {
            echo "<tr><td colspan='6'>Nenhum entrada neste mês!</td></tr>";
        } else {
            echo "<tr><td colspan='6' class='total-line'>" . number_format($total_entrada, 2) . "</td></tr>";
        }
        ?>
    </tbody>
</table>
<table class="tbl-relatorio">
    <thead>
        <tr>
            <th>Saída</th>
            <th colspan="2">Tesoureiro</th>
            <th>Data</th>
            <th>Valor</th>
        </tr>
    </thead>
    <tbody>
        <?php
        foreach ($data[1] as $saida) {
            echo "<tr>";

            echo "<td>" . $saida->beanTipoSaida->descricao . "</td>";
            echo "<td>" . $saida->beanTesoureiro->beanMembro->nome . "</td>";
            echo "<td></td>";
            echo "<td>" . $saida->data . "</td>";
            echo "<td class='valor'>" . number_format($saida->valor, 2) . "</td>";

            echo "</tr>";

            $total_saida += $saida->valor;
        }

        if (empty($data[0])) {
            echo "<tr><td colspan='6'>Nenhuma saída neste mês!</td></tr>";
        } else {
            echo "<tr><td colspan='5' class='total-line'>" . $total_saida . "</td></tr>";
        }
        ?>
    </tbody>
</table>

<div id="totais">
    <div class="relatorio-totais">
        <table>
            <thead>
                <tr>
                    <th colspan="2">Totais</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Total de dízimo</td>
                    <td><?php echo number_format($total_dizimo, 2); ?></td>
                </tr>
                <tr>
                    <td>Total de Oferta</td>
                    <td><?php echo number_format($total_oferta, 2); ?></td>
                </tr>
                <tr>
                    <td>Outras entradas</td>
                    <td><?php echo number_format($total_outra_entradas, 2); ?></td>
                </tr>
                <tr>
                    <td>Total de saída</td>
                    <td><?php echo number_format($total_saida, 2); ?></td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <th><b>Saldo em caixa</b></th>
                    <th><span class="saldo"><?php echo number_format($data[2], 2); ?></span></th>
                </tr>
            </tfoot>
        </table>
    </div>

    <div class="relatorio-totais">
        <table>
            <thead>
                <tr colspan="2">
                    <th>Tipos de entrada</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Cartão</td>
                    <td><?php echo number_format($total_cartao, 2); ?></td>
                </tr>
                <tr>
                    <td>Cheque</td>
                    <td><?php echo number_format($total_cheque, 2); ?></td>
                </tr>
                <tr>
                    <td>Dinheiro</td>
                    <td><?php echo number_format($total_dinheiro, 2); ?></td>
                </tr>
            </tbody>
        </table>
    </div>
</div>
<label class="tit-periodo">Impresso por: <?php echo ucwords($_SESSION["sis_nome"]); ?></label>
<img src="<?php echo BASE_URL; ?>images/logo-agua.png" class="right" />